package com.hgx.mybatis.plus.more.injector;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * Author:     hanguixian
 * Date:     2019/9/8 23:37
 * Description: 自定方法处理
 */
public class MysqlDeleteAll extends AbstractMethod {

    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        //注入的SQL语句
        String sql = "delete from " + tableInfo.getTableName();
        //注入的方法名   一定要与EmployeeMapper接口中的方法名一致
        String method = "deleteAll";

        //构造SqlSource对象
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        //第三个参数必须和baseMapper的自定义方法名一致
        //构造一个删除的MappedStatement
        return this.addDeleteMappedStatement(mapperClass, method, sqlSource);
    }
}